package com.hx.product.controller;


import com.hx.common.annotation.Log;
import com.hx.common.core.controller.BaseController;
import com.hx.common.core.domain.AjaxResult;
import com.hx.common.core.page.TableDataInfo;
import com.hx.common.enums.BusinessType;
import com.hx.common.utils.poi.ExcelUtil;
import com.hx.product.domain.Images;
import com.hx.product.service.IImagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品图片（详情）Controller
 * 
 * @author Chicken Brother
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/images")
public class ImagesController extends BaseController
{
    @Autowired
    private IImagesService imagesService;

    /**
     * 查询商品图片（详情）列表
     */
    @PreAuthorize("@ss.hasPermi('product:images:list')")
    @GetMapping("/list")
    public TableDataInfo list(Images images)
    {
        startPage();
        List<Images> list = imagesService.selectImagesList(images);
        return getDataTable(list);
    }

    /**
     * 导出商品图片（详情）列表
     */
    @PreAuthorize("@ss.hasPermi('product:images:export')")
    @Log(title = "商品图片（详情）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Images images)
    {
        List<Images> list = imagesService.selectImagesList(images);
        ExcelUtil<Images> util = new ExcelUtil<Images>(Images.class);
        util.exportExcel(response, list, "商品图片（详情）数据");
    }

    /**
     * 获取商品图片（详情）详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:images:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imagesService.selectImagesById(id));
    }

    /**
     * 新增商品图片（详情）
     */
    @PreAuthorize("@ss.hasPermi('product:images:add')")
    @Log(title = "商品图片（详情）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Images images)
    {
        return toAjax(imagesService.insertImages(images));
    }

    /**
     * 修改商品图片（详情）
     */
    @PreAuthorize("@ss.hasPermi('product:images:edit')")
    @Log(title = "商品图片（详情）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Images images)
    {
        return toAjax(imagesService.updateImages(images));
    }

    /**
     * 删除商品图片（详情）
     */
    @PreAuthorize("@ss.hasPermi('product:images:remove')")
    @Log(title = "商品图片（详情）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imagesService.deleteImagesByIds(ids));
    }
}
